<template>
    <div>
        <el-button type="primary" @click="dialogFormVisible = true">增加</el-button>
        <el-dialog title="增加" :visible.sync="dialogFormVisible">
            <el-form :model="student">
                <el-form-item label="姓名" :label-width="formLabelWidth">
                    <el-input
                        v-model="student.name"
                        autocomplete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="年龄" :label-width="formLabelWidth">
                    <el-input
                        v-model="student.age"
                        autocomplete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="性别" :label-width="formLabelWidth">
                    <el-radio-group v-model="student.gender">
                        <el-radio label="男">男</el-radio>
                        <el-radio label="女">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="handleClick"
                    >确 定</el-button
                >
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { insert } from "../../services/student";
export default {
    data() {
        return {
            student: {},
            dialogFormVisible: false,
            formLabelWidth: '120px'
        };
    },
    methods: {
        async handleClick() {
            console.log(this.student);
            await insert(this.student);
            this.$emit("show");
            this.dialogFormVisible = false;
        },
    },
};
</script>

<style>
</style>